Skip to content

fix: empty ID for derived accounts leading to state saving failures#206

Draft
ulissesferreira wants to merge 1 commit intomainfrom
NEB-555-unable-to-discover-accounts
Draft

fix: empty ID for derived accounts leading to state saving failures#206
ulissesferreira wants to merge 1 commit intomainfrom
NEB-555-unable-to-discover-accounts

Conversation

@ulissesferreira
Copy link
Contributor

@ulissesferreira ulissesferreira commented Feb 16, 2026

Explanation

The existing codebase conflates derived accounts, which haven't been persisted, with accounts that are already part of the Tron Snap. Not being strict about this lead to the bug reported here. We can do better, creating a more clear separation and favoring that over being "smart" and using less functions.

This PR:

  • Creates a specific type for these accounts
  • Creates a specific function for checking activity of an address (useful in the discovery process)
  • Removes an unnecessary barrel file

References

Closes NEB-555
Closes MetaMask/metamask-extension#40098

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@ulissesferreira ulissesferreira requested a review from a team as a code owner February 16, 2026 12:15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will notice that the findByIds method incorrectly returned null as a possible type. That made no sense since when you can't find something by IDs you simply return an empty array instead of an array with the results... Changed that.

});

return {
id: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of having the ID generated separately from the rest of the account object?


const mappedTransactions = TransactionMapper.mapTransactions({
scope,
account: account as TronKeyringAccount,
Copy link
Contributor Author

@ulissesferreira ulissesferreira Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔪 evil

const privateKeyHex = node.privateKey.slice(2);

// Derive address from public key (cheaper than from private key)
const ethAddress = computeAddress(node.publicKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an eth addres... It's in hexadecimal format. Let's call things by their appropriate names.

});

return {
id: '',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very evil... The source of the bug basically... Was a clear sign that separation was needed here.

};
}

async create(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was something I always hated. Why pass in an ID when creating the account? The answer is we wanted to be able to rollback account creations from the handler method in case we could not emit them here. So we stored the ID and caught errors and deleted the account from the state if it occurred. That is very convoluted. Simply move the logic to the service, the way it should be.

@ulissesferreira ulissesferreira marked this pull request as draft February 16, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: error log during account discovery

2 participants